package com.sghd.fight.module.game.service.skill.effect;

import com.sghd.fight.module.game.config.BuffConfig;
import com.sghd.fight.module.game.config.SkillConfig;
import com.sghd.fight.module.game.core.model.Buff;
import com.sghd.fight.module.game.core.model.Unit;
import com.sghd.fight.module.game.service.room.IRoom;
import com.sghd.fight.module.game.service.skill.ConfigService;
import com.sghd.fight.module.game.service.skill.Context;
import com.sghd.pojo.fight.game.*;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author frank
 * @date 2018-12-07 10:44
 * @desc 回春术
 **/
@Component
public class RejuvenationEffect implements Effect {
    @Autowired
    private ConfigService configService;

    @Override
    public void execute(Context context, IRoom room, Unit owner, Unit target, Map<String, Object> ctx, SkillReport skillReport, TargetReport targetReport, SkillConfig config) {
        int buffId = MapUtils.getInteger(ctx, Effect.BUFF_ID);
        BuffConfig buffConfig = configService.getBuff(buffId);
        Buff buff = getBuff(config, buffConfig, ctx, owner, target);
        int extraRecover = getAddedHp(owner, room, config.getType());//五行额外提供的hp恢复量
        buff.setValue(buff.getValue() + extraRecover);
        context.addBuff(target, buff);
        context.addValue(target, UnitValue.HP, buff.getValue());//立即回复血量
        targetReport.addValue(ValueItem.valueOf(UnitValue.HP, buff.getValue()));
        targetReport.addBuff(BuffReport.valueOf(buffId, buff.getType(), buff.getValue(), buff.getTime(), buff.getLevel()));
    }

    @Override
    public EffectType getType() {
        return EffectType.SK_REJUVENATION;
    }
}
